home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _utilities / utilities / 004 / gamesuit / !Amnesia / AmsHelp / StartHere < prev    next >
Text File  |  1994-08-19  |  3KB  |  84 lines

  1. Start Here - Amnesia - Version 1.00
  2. ===================================
  3.  
  4. This file contains information for the inexperienced programmer about entering numbers in binary and hexadecimal.  If you already know how to do this, move to the Basics document.
  5.  
  6. One thing I will say to experienced users is BE CAREFUL WHEN USING << IN BASIC.  It has a low priority, so 1 + 1 << 5 is evaluated as (1+1)<<5, and worse still X AND 1<<3 is evaluted as (X AND 1) << 3.  Use brackets like X AND (1<<3).
  7.  
  8. Binary
  9. ------
  10.  
  11. Computers work with binary numbers - zeroes and ones.  To use Amnesia you need to know a bit about how binary numbers work.
  12.  
  13. As we move from right to left in a binary number, each figure is worth double the one to the right of it, so
  14.  
  15. Binary   |   Decimal equivalent
  16.  
  17.       1         1    
  18.      10         2 
  19.     100         4
  20.    1000         8  
  21.   10000        16   
  22.  100000        32
  23.      
  24.  and so on....
  25.  
  26. Each of the zeroes or ones in a binary number is a 'bit'.  The bit on the far right is called the least significant bit, bit zero, or the LSB, and the bit on the far left is the most significant bit (MSB).  Just about all numbers youæll encounter when programming your Acorn computer are 32 bits long, so the MSB is bit 31.
  27.  
  28. In BASIC we can enter numbers in various ways.
  29.  
  30. %100000     : direct binary
  31. 1<<5        : a number and a shift value
  32. 32          : the decimal equivalent
  33. &20         : the hexadecimal equivalent
  34.  
  35. Shift values are useful when using Amnesia.  The << symbol shifts a number a certain number of binary places to the left. So
  36.  
  37. %11011 << 3 = %11011000
  38.  
  39. Equivalent to 27 << 3 = 216 in decimal
  40.  
  41. BASIC will convert between binary and other forms for you.  Try
  42.  
  43. PRINT %11011
  44. PRINT %11011 << 3
  45.  
  46. You may have noticed that <<3 is equivalent to multiplying by 8, just as <<4 is equivalent to multiplying by 16, and <<5 multiplying by 32 etc.
  47.  
  48. Hexadecimal is useful as it's easy to convert to and from binary.  All you need to know are the 16 numbers and letters in binary.
  49.  
  50. 0000 = &0,  0001 = &1,   0010 = &2,  0011 = &3,     
  51. 0100 = &4,  0101 = &5,   0110 = &6,  0111 = &7,     
  52. 1000 = &8,  1001 = &9,   1010 = &A,  1011 = &B,     
  53. 1100 = &C,  1101 = &D,   1110 = &E,  1111 = &F.
  54.  
  55. Then you can chop up a binary number like this.
  56.  
  57. %01100100011101010110001101010001
  58.  
  59. splits up as    
  60.  
  61. %0110 0100 0111 0101 0110 0011 0101 0001
  62.  
  63. whis equals
  64.  
  65. &64756351
  66.  
  67. by exchanging each four binary digits for one hexadecimal digit.
  68.  
  69. So, when the Amnesia help files talk about using bit 11, youæll know that you can enter that as any of %100000000000, 1<<11, &800, or 2048.
  70.  
  71. Try experimenting in BASIC.  Here are some type of commands to use.
  72.  
  73. A=%11010101    let A= a number in binary
  74. A=&FC0         let A= a number in hexadecimal
  75.  
  76. PRINT ~A       Print out A in hexadecimal
  77.  
  78. and the exotic
  79.  
  80. *Eval 16_FC0
  81. *Eval 36_ANDY
  82.  
  83. *Eval will convert any base up to base 36 into decimal!  Use 16_ for hex and 2_ for binary.
  84.